/*
 * @Author: 晟松
 * @Date: 2021-12-13 13:05:58
 * @LastEditors: 晟松
 * @LastEditTime: 2022-02-04 22:38:15
 * @FilePath: \mini-vue3d:\Code\node\koa2\volunteer-service\src\main\util\test.js
 * @Description: 解析xlsx格式的表格文件，主要是用于处理居委会和辅导员上传的学生和居民信息
 */
let xlsx = require("node-xlsx");
const fs = require("fs");
const path = require("path");
// var fetch = require("node-fetch");
// var request = require("request");

/**
 * @description:
 * @param {*} fileName xlsx文件的名字，因为文件都是存在upload目录下的
 * @param {*} type xlsx文件是居民的还是学生的，默认居民
 * @return {*}
 */
const xlsxAnalysis = (fileName, type = "resident", filePath) => {
    console.log("fileName1: ", fileName, typeof fileName);
    console.log("filePath1: ", filePath, typeof filePath);
    if (!filePath) filePath = path.resolve(__dirname, "../../upload/" + fileName);

    console.log("filePath2: ", filePath, typeof filePath);

    // 解析得到文档中的所有 sheet
    let sheets = xlsx.parse(filePath);

    let minePath = path.resolve("D:\\Code\\node\\koa2\\volunteer-service\\src\\upload\\" + "testStudent-1.xlsx");
    console.log("minePath1: ", minePath, typeof minePath);

    filePath = path.resolve("D:\\Code\\node\\koa2\\volunteer-service\\src\\upload\\" + fileName);
    console.log("filePath3: ", filePath);
    -
    console.log("sheets: ", sheets, fs.readFileSync(minePath), fs.readFileSync(filePath));
};

xlsxAnalysis("testStudent1.xlsx");


